<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>flatbuttonrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_flatbuttonrenderer.js.html">flatbuttonrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Similiar functionality of {@link goog.ui.ButtonRenderer},
<a name="line17"></a> * but uses a &lt;div&gt; element instead of a &lt;button&gt; or &lt;input&gt; element.
<a name="line18"></a> *
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.ui.FlatButtonRenderer&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line24"></a>goog.require(&#39;goog.ui.Button&#39;);
<a name="line25"></a>goog.require(&#39;goog.ui.ButtonRenderer&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.INLINE_BLOCK_CLASSNAME&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.registry&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Flat renderer for {@link goog.ui.Button}s.  Flat buttons can contain
<a name="line32"></a> * almost arbitrary HTML content, will flow like inline elements, but can be
<a name="line33"></a> * styled like block-level elements.
<a name="line34"></a> * @constructor
<a name="line35"></a> * @extends {goog.ui.ButtonRenderer}
<a name="line36"></a> */
<a name="line37"></a>goog.ui.FlatButtonRenderer = function() {
<a name="line38"></a>  goog.ui.ButtonRenderer.call(this);
<a name="line39"></a>};
<a name="line40"></a>goog.inherits(goog.ui.FlatButtonRenderer, goog.ui.ButtonRenderer);
<a name="line41"></a>goog.addSingletonGetter(goog.ui.FlatButtonRenderer);
<a name="line42"></a>
<a name="line43"></a>
<a name="line44"></a>/**
<a name="line45"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line46"></a> * by this renderer.
<a name="line47"></a> * @type {string}
<a name="line48"></a> */
<a name="line49"></a>goog.ui.FlatButtonRenderer.CSS_CLASS = goog.getCssName(&#39;goog-flat-button&#39;);
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * Returns the control&#39;s contents wrapped in a div element, with
<a name="line54"></a> * the renderer&#39;s own CSS class and additional state-specific classes applied
<a name="line55"></a> * to it, and the button&#39;s disabled attribute set or cleared as needed.
<a name="line56"></a> * Overrides {@link goog.ui.ButtonRenderer#createDom}.
<a name="line57"></a> * @param {goog.ui.Button} button Button to render.
<a name="line58"></a> * @return {Element} Root element for the button.
<a name="line59"></a> */
<a name="line60"></a>goog.ui.FlatButtonRenderer.prototype.createDom = function(button) {
<a name="line61"></a>  var classNames = this.getClassNames(button);
<a name="line62"></a>  var attributes = {
<a name="line63"></a>    &#39;class&#39;: goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; + classNames.join(&#39; &#39;),
<a name="line64"></a>    &#39;title&#39;: button.getTooltip() || &#39;&#39;
<a name="line65"></a>  };
<a name="line66"></a>  return button.getDomHelper().createDom(
<a name="line67"></a>      &#39;div&#39;, attributes, button.getContent());
<a name="line68"></a>};
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * Returns true if this renderer can decorate the element.  Overrides
<a name="line73"></a> * {@link goog.ui.ButtonRenderer#canDecorate} by returning true if the
<a name="line74"></a> * element is a DIV, false otherwise.
<a name="line75"></a> * @param {Element} element Element to decorate.
<a name="line76"></a> * @return {boolean} Whether the renderer can decorate the element.
<a name="line77"></a> */
<a name="line78"></a>goog.ui.FlatButtonRenderer.prototype.canDecorate = function(element) {
<a name="line79"></a>  return element.tagName == &#39;DIV&#39;;
<a name="line80"></a>};
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * Takes an existing element and decorates it with the flat button control.
<a name="line85"></a> * Initializes the control&#39;s ID, content, tooltip, value, and state based
<a name="line86"></a> * on the ID of the element, its child nodes, and its CSS classes, respectively.
<a name="line87"></a> * Returns the element.  Overrides {@link goog.ui.ButtonRenderer#decorate}.
<a name="line88"></a> * @param {goog.ui.Button} button Button instance to decorate the element.
<a name="line89"></a> * @param {Element} element Element to decorate.
<a name="line90"></a> * @return {Element} Decorated element.
<a name="line91"></a> */
<a name="line92"></a>goog.ui.FlatButtonRenderer.prototype.decorate = function(button, element) {
<a name="line93"></a>  goog.dom.classes.add(element, goog.ui.INLINE_BLOCK_CLASSNAME);
<a name="line94"></a>  return goog.ui.FlatButtonRenderer.superClass_.decorate.call(this, button,
<a name="line95"></a>      element);
<a name="line96"></a>};
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Flat buttons can&#39;t use the value attribute since they are div elements.
<a name="line101"></a> * Overrides {@link goog.ui.ButtonRenderer#getValue} to prevent trying to
<a name="line102"></a> * access the element&#39;s value.
<a name="line103"></a> * @param {Element} element The button control&#39;s root element.
<a name="line104"></a> * @return {null} Value not valid for flat buttons.
<a name="line105"></a> */
<a name="line106"></a>goog.ui.FlatButtonRenderer.prototype.getValue = function(element) {
<a name="line107"></a>  // Flat buttons don&#39;t store their value in the DOM.
<a name="line108"></a>  return null;
<a name="line109"></a>};
<a name="line110"></a>
<a name="line111"></a>
<a name="line112"></a>/**
<a name="line113"></a> * Returns the CSS class to be applied to the root element of components
<a name="line114"></a> * rendered using this renderer.
<a name="line115"></a> * @return {string} Renderer-specific CSS class.
<a name="line116"></a> */
<a name="line117"></a>goog.ui.FlatButtonRenderer.prototype.getCssClass = function() {
<a name="line118"></a>  return goog.ui.FlatButtonRenderer.CSS_CLASS;
<a name="line119"></a>};
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>// Register a decorator factory function for Flat Buttons.
<a name="line123"></a>goog.ui.registry.setDecoratorByClassName(goog.ui.FlatButtonRenderer.CSS_CLASS,
<a name="line124"></a>    function() {
<a name="line125"></a>      // Uses goog.ui.Button, but with FlatButtonRenderer.
<a name="line126"></a>      return new goog.ui.Button(null, goog.ui.FlatButtonRenderer.getInstance());
<a name="line127"></a>    });
</pre>


</body>
</html>
